<template>
  <div>
    <div
      class="listBox"
      v-for="(item, index) of list"
      :key="index"
      @click="clickHandler(item.id)"
    >
      <div class="listLeft">
        <img :src="item.pic" alt="" />
      </div>
      <div class="listRight">
        <div class="listTitle">{{ item.name }}</div>
        <div class="listBottom">
          <van-progress
            :percentage="item.schedule || 4"
            :show-pivot="false"
            stroke-width="6px"
            color="#ee0a24"
          />
          <div>已学{{ item.schedule }}%</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { get } from "@/utils/http.js";
export default {
  props: {
    listData: String,
  },
  methods: {
    // myRandom() {
    //   return ~~(Math.random() * 100);
    // },
    clickHandler(id) {
      this.$router.push("/detail/" + id);
    },
  },
  data() {
    return {
      list: [],
    };
  },
  async mounted() {
    // console.log(this.listData);
    this.list = this.listData.split(",").map(async (item) => {
      // console.log(get(`/session/detail/${item}`));
      let data = await get(`/session/detail/${item}`);
      // console.log(data);
      return {
        id: data.id,
        name: data.intro.name,
        pic: data.intro.detail.pic,
        schedule: ~~(Math.random() * 100),
      };
    });
    // console.log(this.list);

    Promise.all(this.list).then((arr) => {
      this.list = arr;
      // console.log(arr);
    });
    // console.log(this.listData.lately);
  },
};
</script>

<style lang="scss" scoped>
.listBox {
  display: flex;
  margin-top: 20px;
  margin-left: 20px;
  .listLeft {
    width: 127px;
    height: 83px;
    border-radius: 10px;
    background-color: rebeccapurple;
    img {
      width: 100%;
      height: 100%;
      border-radius: 10px;
    }
  }
  .listRight {
    width: 200px;
    height: 80px;
    margin-left: 20px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    .listTitle {
      font-size: 16px;
    }
    .listBottom {
      display: flex;
      font-size: 12px;
      align-items: center;
      //   margin-bottom: 2px;
      div {
        color: #bbb;
      }
    }
    .van-progress {
      width: 125px;
      margin-right: 18px;
    }
  }
}
</style>